#
# (C) COPYRIGHT 2010-2018 ARM Limited. All rights reserved.
#
# This program is free software and is provided to you under the terms of the
# GNU General Public License version 2 as published by the Free Software
# Foundation, and any use by you of this program is subject to the terms
# of such GNU licence.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# SPDX-License-Identifier: GPL-2.0
#
#

import sys
Import('env')

SConscript( 'tests/sconscript' )

mock_test = 0

# Source files required for kbase.
kbase_src = [
	Glob('*.c'),
	Glob('backend/*/*.c'),
	Glob('internal/*/*.c'),
	Glob('ipa/*.c'),
	Glob('platform/%s/*.c' % env['platform_config']),
	Glob('thirdparty/*.c'),
]

if env['platform_config']=='juno_soc':
	kbase_src += [Glob('platform/devicetree/*.c')]
else:
	kbase_src += [Glob('platform/%s/*.c' % env['platform_config'])]

if Glob('#kernel/drivers/gpu/arm/midgard/tests/internal/src/mock') and env['unit'] == '1':
	kbase_src += [Glob('#kernel/drivers/gpu/arm/midgard/tests/internal/src/mock/*.c')]
	mock_test = 1

make_args = env.kernel_get_config_defines(ret_list = True) + [
	'PLATFORM=%s' % env['platform'],
	'MALI_KERNEL_TEST_API=%s' % env['debug'],
	'MALI_UNIT_TEST=%s' % env['unit'],
	'MALI_RELEASE_NAME=%s' % env['mali_release_name'],
	'MALI_MOCK_TEST=%s' % mock_test,
	'MALI_CUSTOMER_RELEASE=%s' % env['release'],
	'MALI_USE_CSF=%s' % env['csf'],
	'MALI_COVERAGE=%s' % env['coverage'],
]

kbase = env.BuildKernelModule('$STATIC_LIB_PATH/mali_kbase.ko', kbase_src,
                              make_args = make_args)

if 'smc_protected_mode_switcher' in env:
	env.Depends('$STATIC_LIB_PATH/mali_kbase.ko', '$STATIC_LIB_PATH/smc_protected_mode_switcher.ko')

env.KernelObjTarget('kbase', kbase)

env.AppendUnique(BASE=['cutils_linked_list'])
